﻿@model List<SelectListItem>

@{
    string title = ViewBag.Title;
    string nameId = ViewBag.NameId;
    int selectCount = Model.Where(x => x.Selected).Count();
}

@if (Model.Count > 0)
{
    <div class="mega-menu"> 
        <div class="dropdown mega-fw">
            <button data-toggle="dropdown" class="dropdown-toggle btn btn-default">
                @title @(selectCount > 0 ? "(" + selectCount + ")" : "") &nbsp; &nbsp; <b class="caret"></b>
            </button>
            <div class="dropdown-menu">
                @if (Model.Any(x => x.Selected == true))
                {
                    <div class="row">
                        <div class="col-md-3 col-sm-4 col-xs-6">
                            @foreach (var item in Model.Where(x => x.Selected == true))
                            {

                                <p>
                                    <a class="no-href" data-id="@item.Value" onclick="RemoveFilter(this)">
                                        @item.Text
                                        <input type="checkbox" name="@nameId" value="@item.Value" checked hidden />
                                    </a>
                                </p>
                            }
                            <hr />
                            <button type="button" class="btn btn-sm btn-danger" onclick="RemoveAllFilter(this)">
                                <span class="glyphicon glyphicon-remove"></span> Xóa tất cả
                            </button>
                        </div>
                        <div class="col-md-9 col-sm-8 col-xs-6" style="border-left: 1px solid #ddd; height: 300px; overflow-y: scroll;">
                            <div class="row">
                                @foreach (var item in Model.Where(x => x.Selected == false))
                                {
                                    <div class="col-md-4 col-sm-6">
                                        <p>
                                            <a class="no-href" data-id="@item.Value" onclick="AddFilter(this)">
                                                @item.Text
                                                <input type="checkbox" name="@nameId" value="@item.Value" hidden />
                                            </a>
                                        </p>
                                    </div>
                                }
                            </div>
                        </div>
                    </div>
                }
                else
                {
                    <div class="row" style="height: 300px; overflow-y: scroll;">
                        @foreach (var item in Model)
                        {
                            <div class="col-md-3 col-sm-4 col-xs-6">
                                <p>
                                    <a class="no-href" data-id="@item.Value" onclick="AddFilter(this)">
                                        @item.Text
                                        <input type="checkbox" name="@nameId" value="@item.Value" hidden />
                                    </a>
                                </p>
                            </div>
                        }
                    </div>
                }
            </div>
        </div>
    </div>
}
